package com.tinyideatech.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyideatech.common.utils.DateUtils;
import com.tinyideatech.system.entity.MallPay;
import com.tinyideatech.system.mapper.MallPayMapper;
import com.tinyideatech.system.service.IMallPayService;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangy-5
 * @date 2019-08-27
 */
@Service
public class MallPayServiceImpl extends ServiceImpl<MallPayMapper, MallPay> implements IMallPayService {

    @Autowired
    private MallPayMapper mallPayMapper;

    @Override
    public XSSFWorkbook downloadRecorder() {
        List<MallPay> mallPays = mallPayMapper.selectList(null);
        XSSFWorkbook wb = new XSSFWorkbook();
        Sheet sheet = wb.createSheet("mall_pay");
        Row titleRow = sheet.createRow(0);
        titleRow.createCell(1).setCellValue("支付编号");
        titleRow.createCell(2).setCellValue("用户名称");
        titleRow.createCell(3).setCellValue("设备编号");
        titleRow.createCell(4).setCellValue("关联订单编号");
        titleRow.createCell(5).setCellValue("总价格");
        titleRow.createCell(6).setCellValue("数量");
        titleRow.createCell(7).setCellValue("创建时间");
        int cell = 1;
        for (MallPay mallPay : mallPays) {
            Row row = sheet.createRow(cell);
            row.createCell(0).setCellValue(cell);
            row.createCell(1).setCellValue(mallPay.getPayId());
            row.createCell(2).setCellValue(mallPay.getUsername());
            row.createCell(3).setCellValue(mallPay.getDeviceId());
            row.createCell(4).setCellValue(mallPay.getOrderId());
            row.createCell(5).setCellValue(mallPay.getPrice());
            row.createCell(6).setCellValue(mallPay.getSize());
            row.createCell(7).setCellValue(DateUtils.parseDateToStr("yyyy/MM/dd", mallPay.getCreateTime()));
            cell++;
        }
        return wb;
    }
}
